<!--
 * @description: 
 * @Author: jhw
 * @Date: 2023-05-13 22:45:32
 * @LastEditors: jhw
 * @LastEditTime: 2023-05-14 00:42:34
-->
<template>
  <div class="table-box">
    <div v-for="(item, index) in tableData" :key="index" :style="tdWidth(item)">
      <div class="table-box__td">
        <div class="table-box__td__header">{{ item.name }}</div>
        <div class="table-box__td__value">
          <slot :name="item.slotName || 'tableValue'">{{ item.value }}</slot>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { PropType } from 'vue';
type Table = {
  name: string | number;
  value: string | number;
  slotName: string;
  interval: number;
  hold: number;
};

defineProps({
  tableData: {
    type: Array as PropType<Table[]>,
    default: () => [],
  },
});

const tdWidth = (type: { interval: number; hold: number }) => {
  let width = (100 / type.interval) * type.hold;
  return { width: `${width}%` };
};
</script>

<style lang="scss" scoped>
.table-box {
  display: flex;
  flex-wrap: wrap;
  width: 100%;

  .table-box__td {
    min-height: 50px;
    display: flex;
    width: 100%;
    height: 100%;

    .table-box__td__header {
      padding: 20px;
      width: 120px;
      height: 100%;
      color: #000;
      border: 1px solid #ebeaea;
      background-color: #f4faff;
    }

    .table-box__td__value {
      flex: 1;
      color: #000;
      box-sizing: border-box;
      border: 1px solid #ebeaea;
      padding: 10px 8px;
    }
  }
}
</style>
